
class StorageService {
  store = window.sessionStorage
  set(key, value) {
    try {
      // 把里面的值转换成json对象
      value = JSON.stringify(value)
    } catch (e) {
      // 抛出一个错误
      value = e
    }

    this.store.setItem(key, value)

  }

  get(key) {
    let value = this.store.getItem(key)
    if (value) {
      try {
        value = JSON.parse(value)
      } catch (e) {
        value = e
      }
    }
    return value
  }
  remove(key) {
    this.store.removeItem(key)
  }

  clear() {
    this.store.clear()
  }
}
export default new StorageService()
